import 'dart:math';

import 'package:flutter/material.dart';

import '../constants.dart';
import 'linear_graph.dart';

class Person {
  String name;
  Color color;
  int messageNum;
  Person({
    required this.name,
    required this.color,
    required this.messageNum,
  });
}

class PanelCenterPage extends StatefulWidget {
  const PanelCenterPage({Key? key}) : super(key: key);

  @override
  State<PanelCenterPage> createState() => _PanelCenterPageState();
}

class _PanelCenterPageState extends State<PanelCenterPage> {
  List<Person> persons = [
    Person(
        name: 'Theia Brown',
        color: Constants.orangeLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Fariha Odling',
        color: Constants.redLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Viola Willis',
        color: Constants.blueLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Emmett Forrest',
        color: Constants.orangeLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Nick Jarvis',
        color: Constants.greenLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Amit Clavesia',
        color: Constants.orangeLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Amalie Howardeia',
        color: Constants.redLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Campbell Britton',
        color: Constants.blueLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Haley Mellor ',
        color: Constants.redLight,
        messageNum: Random().nextInt(10)),
    Person(
        name: 'Harlen Higgins',
        color: Constants.greenLight,
        messageNum: Random().nextInt(10)),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.only(
                left: Constants.kPadding / 2,
                right: Constants.kPadding / 2,
                top: Constants.kPadding / 2,
              ),
              child: Card(
                color: Constants.purpleLight,
                elevation: 3,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(50),
                ),
                child: Container(
                  width: double.infinity,
                  child: ListTile(
                    title: Text(
                      'Products Available',
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                    subtitle: Text(
                      '82% of Products Avail',
                      style: TextStyle(color: Colors.white),
                    ),
                    trailing: Chip(
                      label: Text(
                        '20,500',
                        style: TextStyle(color: Colors.white),
                      ),
                    ),
                  ),
                ),
              ),
            ),
            BarChartSample2(),
            Padding(
              padding: EdgeInsets.only(
                left: Constants.kPadding / 2,
                right: Constants.kPadding / 2,
                top: Constants.kPadding,
                bottom: Constants.kPadding,
              ),
              child: Card(
                color: Constants.purpleLight,
                elevation: 3,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(20),
                ),
                child: Column(
                  children: List.generate(
                    persons.length,
                    (index) => ListTile(
                      leading: CircleAvatar(
                        radius: 15,
                        backgroundColor: persons[index].color,
                        child: Text(
                          persons[index].name.substring(0, 1),
                          style: TextStyle(color: Colors.white),
                        ),
                      ),
                      title: Text(
                        persons[index].name,
                        style: TextStyle(color: Colors.white),
                      ),
                      trailing: Stack(
                        children: [
                          IconButton(
                            onPressed: () {},
                            icon: Icon(
                              Icons.message,
                              color: Colors.white,
                            ),
                          ),
                          if (persons[index].messageNum > 0)
                            Positioned(
                              child: CircleAvatar(
                                backgroundColor: Colors.pink,
                                radius: 8,
                                child: Text(
                                  persons[index].messageNum.toString(),
                                  style: TextStyle(
                                    fontSize: 10,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            )
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
